$(async function () {
    // 获取分类id
    const cate_id =parseInt(location.search.split('=')[1])
    // 图片的基准地址
    const img_host = 'http://localhost:8081'
     // 1.获取分类数据
     const cates = await axios.get('api/home/cates')
     const catesHtml = template('catesTpl', {
         cates,
         cate_id
     })
     $('#nav ul').html(catesHtml)
     // 2.获取分类名称
     const cate_name = cates.find(v => v.id === cate_id)['cate_name']
     $('.news .title h3').html(cate_name)


    // 3.获取图片新闻
    const imgsData = await axios.get('api/home/getImgNews', {
        params: {
            cate_id
        }
    })
    
    const imgsHtml = template('imgsTpl', {
        imgsData,
        img_host
    })
    $('#main1 ul').html(imgsHtml)

    // 3.获取最新新闻
    const newNewsData = await axios.get('api/home/getNewNews', {
        params: {
            cate_id
        }
    })
    const newNewsHtml = template('newNewsTpl', {
        newNewsData
    })
    $('.new-news').html(newNewsHtml)
})